package com.ibm.crl.sb.thread.czbk;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class ThreadScopeShareData {

	private Map<Thread, Integer> threadData = new HashMap<Thread, Integer>();

	public ThreadScopeShareData() {
		for (int i = 0; i < 2; i++) {
			new Thread(new Runnable() {
				@Override
				public void run() {
					int data = new Random().nextInt();
					System.out.println(Thread.currentThread().getName()
							+ "has put data" + data);
					threadData.put(Thread.currentThread(), data);
					new A().getData();
					new B().getData();
				}

			}).start();
		}
	}

	public static void main(String[] args) {
		new ThreadScopeShareData();
	}

	class A {

		public void getData() {
			int data = threadData.get(Thread.currentThread());
			System.out.println(Thread.currentThread().getName() + "A get data"
					+ data);
		}

	}

	class B {
		public void getData() {
			int data = threadData.get(Thread.currentThread());
			System.out.println(Thread.currentThread().getName() + "B get data"
					+ data);
		}

	}
}
